package com.mentalhealthplatform.studentV3.controller;


import com.mentalhealthplatform.studentV3.dto.StudentDTOV3;
import com.mentalhealthplatform.studentV3.service.StudentServiceV3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

/**
 * @author Pear
 */
@RestController
@RequestMapping("/api/v3/students")
public class StudentControllerV3 {

    @Autowired
    private StudentServiceV3 studentService;

    // 根据用户名获取教师信息
    @GetMapping("/username/{username}")
    public ResponseEntity<StudentDTOV3> getStudentByUsername(@PathVariable String username) {
        Optional<StudentDTOV3> teacherDTO = studentService.getstudentdtoByUsername(username);
        return teacherDTO.map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    // 根据姓名模糊查询教师列表
    @GetMapping("/name")
    public ResponseEntity<List<StudentDTOV3>> getStudentsByName(@RequestParam String name) {
        List<StudentDTOV3> students = studentService.getstudentsdtoByName(name);
        return ResponseEntity.ok(students);
    }

    // 获取所有教师列表
    @GetMapping
    public ResponseEntity<List<StudentDTOV3>> getAllStudents() {
        List<StudentDTOV3> teachers = studentService.getAllStudentsDTO();
        return ResponseEntity.ok(teachers);
    }
}

